import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import  axios from 'axios'
import  VueAxios from 'vue-axios'

// mock的开关
const mock = false;
if (mock) {
  require('./mock/mock')
}

Vue.config.productionTip = false

//引入ElementUI样式
import 'element-ui/lib/theme-chalk/index.css'

//使用ElementUI
Vue.use(ElementUI)
//使用axios
Vue.use(VueAxios,axios);

//添加向后端发起请求的服务器地址
axios.defaults.baseURL = "http://127.0.0.1:80/api";

//设置请求的超时时间
axios.defaults.timeout = 5000;

//接口对request的拦截
axios.interceptors.request.use(function (request) {
  console.log("pre-axios");
  return request;
})
//接口对response的拦截
axios.interceptors.response.use(function (response) {
  console.log("after-axios");
  if(response.status === 200){
    return response.data;
  }else{
    this.$message({
      message:'访问后台出错',
      duration:1000,
      type:'error'
    })
    return Promise.reject(response);
  }

})



new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
